<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Support\Facades\Log;

class BenchMark
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $startTime = microtime(true);
        $response = $next($request);
        $runTime = microtime(true) - $startTime;
        Log::info('runtime',[
            'url' => $request->url(),
            'params' => $request->input(),
            'stime' => $startTime,
            'time' => sprintf('%10.10f ms',$runTime),
        ]);
        return $response;
    }
}
